package layers.ants;

import layers.agents.AgentInterface;
import layers.physical.Crossroad;
import events.antEvents.AntCreatedEvent;
import events.antEvents.AntDiedEvent;
import framework.events.EventBroker;
import framework.utils.IdGenerator;

public abstract class Ant implements AntTickListener{
	
	private AgentInterface agent;
	private Crossroad crossroad;
	private int id;

	public Ant(Crossroad crossroad, AgentInterface agent){
		if(crossroad == null)
			throw new IllegalArgumentException("Crossroad cannot be null.");
		this.crossroad = crossroad;
		this.id = IdGenerator.getIdGenerator().getNextId(Ant.class);
		this.agent = agent;
		EventBroker.getEventBroker().notifyAll(new AntCreatedEvent(this));
	}
	
	public abstract void processAntTick();

	protected void die() {
		this.crossroad = null;
		EventBroker.getEventBroker().notifyAll(new AntDiedEvent(this));
	}
	
	protected Crossroad getCrossroad(){
		return this.crossroad;
	}
	
	protected void setCrossroad(Crossroad crossroad) {
		this.crossroad = crossroad;
	}

	public int getId(){
		return this.id;
	}

	protected void setAgent(AgentInterface agent) {
		this.agent = agent;
	}

	protected AgentInterface getAgent() {
		return agent;
	}
}
